package com.fanshuai.lifecycle.aware;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 获取全局ApplicationContext
 */
@Component
public class DemoApplicationContext implements ApplicationContextAware {
    private ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
        System.out.println("application context=" + applicationContext);
    }

    public ApplicationContext getContext() {
        return context;
    }
}
